home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1997 December / PC Pro December 1997 CD-Rom coverdisc.iso / symantec / dbAnywh / JAVA.BIN / CLASSES.ZIP / sun / tools / asm / Instruction.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-14  |  10.4 KB  |  827 lines

  1. package sun.tools.asm;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import java.util.Enumeration;
  6. import sun.tools.java.ClassDeclaration;
  7. import sun.tools.java.CompilerError;
  8. import sun.tools.java.Constants;
  9. import sun.tools.java.Environment;
  10. import sun.tools.java.FieldDefinition;
  11. import sun.tools.java.RuntimeConstants;
  12.  
  13. public class Instruction implements Constants {
  14.    int where;
  15.    // $FF: renamed from: pc int
  16.    int field_0;
  17.    int opc;
  18.    Object value;
  19.    Instruction next;
  20.  
  21.    public Instruction(int var1, int var2, Object var3) {
  22.       this.where = var1;
  23.       this.opc = var2;
  24.       this.value = var3;
  25.    }
  26.  
  27.    public int getOpcode() {
  28.       return this.field_0;
  29.    }
  30.  
  31.    public Object getValue() {
  32.       return this.value;
  33.    }
  34.  
  35.    public void setValue(Object var1) {
  36.       this.value = var1;
  37.    }
  38.  
  39.    void optimize(Environment var1) {
  40.       switch (this.opc) {
  41.          case 54:
  42.          case 55:
  43.          case 56:
  44.          case 57:
  45.          case 58:
  46.             if (this.value instanceof LocalVariable && !var1.debug()) {
  47.                this.value = new Integer(((LocalVariable)this.value).slot);
  48.                return;
  49.             }
  50.             break;
  51.          case 153:
  52.          case 154:
  53.          case 155:
  54.          case 156:
  55.          case 157:
  56.          case 158:
  57.          case 198:
  58.          case 199:
  59.             this.value = ((Label)this.value).getDestination();
  60.             if (this.value == this.next) {
  61.                this.opc = 87;
  62.                return;
  63.             }
  64.  
  65.             if (this.next.opc == 167 && this.value == this.next.next) {
  66.                switch (this.opc) {
  67.                   case 153:
  68.                      this.opc = 154;
  69.                      break;
  70.                   case 154:
  71.                      this.opc = 153;
  72.                      break;
  73.                   case 155:
  74.                      this.opc = 156;
  75.                      break;
  76.                   case 156:
  77.                      this.opc = 155;
  78.                      break;
  79.                   case 157:
  80.                      this.opc = 158;
  81.                      break;
  82.                   case 158:
  83.                      this.opc = 157;
  84.                      break;
  85.                   case 198:
  86.                      this.opc = 199;
  87.                      break;
  88.                   case 199:
  89.                      this.opc = 198;
  90.                }
  91.  
  92.                this.value = this.next.value;
  93.                this.next.opc = -2;
  94.                return;
  95.             }
  96.             break;
  97.          case 159:
  98.          case 160:
  99.          case 161:
  100.          case 162:
  101.          case 163:
  102.          case 164:
  103.          case 165:
  104.          case 166:
  105.             this.value = ((Label)this.value).getDestination();
  106.             if (this.value == this.next) {
  107.                this.opc = 88;
  108.                return;
  109.             }
  110.  
  111.             if (this.next.opc == 167 && this.value == this.next.next) {
  112.                switch (this.opc) {
  113.                   case 159:
  114.                      this.opc = 160;
  115.                      break;
  116.                   case 160:
  117.                      this.opc = 159;
  118.                      break;
  119.                   case 161:
  120.                      this.opc = 162;
  121.                      break;
  122.                   case 162:
  123.                      this.opc = 161;
  124.                      break;
  125.                   case 163:
  126.                      this.opc = 164;
  127.                      break;
  128.                   case 164:
  129.                      this.opc = 163;
  130.                      break;
  131.                   case 165:
  132.                      this.opc = 166;
  133.                      break;
  134.                   case 166:
  135.                      this.opc = 165;
  136.                }
  137.  
  138.                this.value = this.next.value;
  139.                this.next.opc = -2;
  140.                return;
  141.             }
  142.             break;
  143.          case 167:
  144.             Label var10 = (Label)this.value;
  145.             Label var11;
  146.             this.value = var11 = var10.getDestination();
  147.             if (var11 == this.next) {
  148.                this.opc = -2;
  149.                return;
  150.             }
  151.  
  152.             if (var11.next != null) {
  153.                switch (var11.next.opc) {
  154.                   case 172:
  155.                   case 173:
  156.                   case 174:
  157.                   case 175:
  158.                   case 176:
  159.                   case 177:
  160.                      this.opc = var11.next.opc;
  161.                      this.value = var11.next.value;
  162.                      return;
  163.                }
  164.             }
  165.             break;
  166.          case 170:
  167.          case 171:
  168.             SwitchData var2 = (SwitchData)this.value;
  169.             var2.defaultLabel = var2.defaultLabel.getDestination();
  170.             Enumeration var3 = var2.tab.keys();
  171.  
  172.             while(var3.hasMoreElements()) {
  173.                Integer var4 = (Integer)var3.nextElement();
  174.                Label var5 = (Label)var2.tab.get(var4);
  175.                var2.tab.put(var4, var5.getDestination());
  176.             }
  177.  
  178.             long var12 = (long)(var1.optimize() ? 2 : 4);
  179.             long var6 = (long)var2.maxValue - (long)var2.minValue;
  180.             long var8 = (long)var2.tab.size();
  181.             this.opc = var6 - var8 <= var8 / var12 ? 170 : 171;
  182.             return;
  183.       }
  184.  
  185.    }
  186.  
  187.    void collect(ConstantPool var1) {
  188.       switch (this.opc) {
  189.          case -3:
  190.             Enumeration var8 = ((TryData)this.value).catches.elements();
  191.  
  192.             while(var8.hasMoreElements()) {
  193.                CatchData var3 = (CatchData)var8.nextElement();
  194.                if (var3.getType() != null) {
  195.                   var1.put(var3.getType());
  196.                }
  197.             }
  198.  
  199.             return;
  200.          case 0:
  201.             if (this.value != null && this.value instanceof ClassDeclaration) {
  202.                var1.put(this.value);
  203.             }
  204.  
  205.             return;
  206.          case 18:
  207.          case 19:
  208.             if (this.value instanceof Integer) {
  209.                int var6 = (Integer)this.value;
  210.                if (var6 >= -1 && var6 <= 5) {
  211.                   this.opc = 3 + var6;
  212.                   return;
  213.                }
  214.  
  215.                if (var6 > -128 && var6 < 128) {
  216.                   this.opc = 16;
  217.                   return;
  218.                }
  219.  
  220.                if (var6 > -32768 && var6 < 32768) {
  221.                   this.opc = 17;
  222.                   return;
  223.                }
  224.             } else if (this.value instanceof Float) {
  225.                float var7 = (Float)this.value;
  226.                if (var7 == 0.0F) {
  227.                   if (Float.floatToIntBits(var7) == 0) {
  228.                      this.opc = 11;
  229.                      return;
  230.                   }
  231.                } else {
  232.                   if (var7 == 1.0F) {
  233.                      this.opc = 12;
  234.                      return;
  235.                   }
  236.  
  237.                   if (var7 == 2.0F) {
  238.                      this.opc = 13;
  239.                      return;
  240.                   }
  241.                }
  242.             }
  243.  
  244.             var1.put(this.value);
  245.             return;
  246.          case 20:
  247.             if (this.value instanceof Long) {
  248.                long var4 = (Long)this.value;
  249.                if (var4 == 0L) {
  250.                   this.opc = 9;
  251.                   return;
  252.                }
  253.  
  254.                if (var4 == 1L) {
  255.                   this.opc = 10;
  256.                   return;
  257.                }
  258.             } else if (this.value instanceof Double) {
  259.                double var5 = (Double)this.value;
  260.                if (var5 == (double)0.0F) {
  261.                   if (Double.doubleToLongBits(var5) == 0L) {
  262.                      this.opc = 14;
  263.                      return;
  264.                   }
  265.                } else if (var5 == (double)1.0F) {
  266.                   this.opc = 15;
  267.                   return;
  268.                }
  269.             }
  270.  
  271.             var1.put(this.value);
  272.             return;
  273.          case 54:
  274.          case 55:
  275.          case 56:
  276.          case 57:
  277.          case 58:
  278.             if (this.value instanceof LocalVariable) {
  279.                FieldDefinition var2 = ((LocalVariable)this.value).field;
  280.                var1.put(var2.getName().toString());
  281.                var1.put(var2.getType().getTypeSignature());
  282.             }
  283.  
  284.             return;
  285.          case 178:
  286.          case 179:
  287.          case 180:
  288.          case 181:
  289.          case 182:
  290.          case 183:
  291.          case 184:
  292.          case 185:
  293.          case 187:
  294.          case 192:
  295.          case 193:
  296.             var1.put(this.value);
  297.             return;
  298.          case 189:
  299.             var1.put(this.value);
  300.             return;
  301.          case 197:
  302.             var1.put(((ArrayData)this.value).type);
  303.             return;
  304.          default:
  305.       }
  306.    }
  307.  
  308.    int balance() {
  309.       switch (this.opc) {
  310.          case -3:
  311.          case -2:
  312.          case -1:
  313.          case 0:
  314.          case 47:
  315.          case 49:
  316.          case 95:
  317.          case 116:
  318.          case 117:
  319.          case 118:
  320.          case 119:
  321.          case 132:
  322.          case 134:
  323.          case 138:
  324.          case 139:
  325.          case 143:
  326.          case 145:
  327.          case 146:
  328.          case 147:
  329.          case 167:
  330.          case 168:
  331.          case 169:
  332.          case 177:
  333.          case 188:
  334.          case 189:
  335.          case 190:
  336.          case 192:
  337.          case 193:
  338.          case 200:
  339.          case 201:
  340.             return 0;
  341.          case 1:
  342.          case 2:
  343.          case 3:
  344.          case 4:
  345.          case 5:
  346.          case 6:
  347.          case 7:
  348.          case 8:
  349.          case 11:
  350.          case 12:
  351.          case 13:
  352.          case 16:
  353.          case 17:
  354.          case 18:
  355.          case 19:
  356.          case 21:
  357.          case 23:
  358.          case 25:
  359.          case 89:
  360.          case 90:
  361.          case 91:
  362.          case 133:
  363.          case 135:
  364.          case 140:
  365.          case 141:
  366.          case 187:
  367.             return 1;
  368.          case 9:
  369.          case 10:
  370.          case 14:
  371.          case 15:
  372.          case 20:
  373.          case 22:
  374.          case 24:
  375.          case 92:
  376.          case 93:
  377.          case 94:
  378.             return 2;
  379.          case 46:
  380.          case 48:
  381.          case 50:
  382.          case 51:
  383.          case 52:
  384.          case 53:
  385.          case 54:
  386.          case 56:
  387.          case 58:
  388.          case 87:
  389.          case 96:
  390.          case 98:
  391.          case 100:
  392.          case 102:
  393.          case 104:
  394.          case 106:
  395.          case 108:
  396.          case 110:
  397.          case 112:
  398.          case 114:
  399.          case 120:
  400.          case 121:
  401.          case 122:
  402.          case 123:
  403.          case 124:
  404.          case 125:
  405.          case 126:
  406.          case 128:
  407.          case 130:
  408.          case 136:
  409.          case 137:
  410.          case 142:
  411.          case 144:
  412.          case 149:
  413.          case 150:
  414.          case 153:
  415.          case 154:
  416.          case 155:
  417.          case 156:
  418.          case 157:
  419.          case 158:
  420.          case 170:
  421.          case 171:
  422.          case 172:
  423.          case 174:
  424.          case 176:
  425.          case 191:
  426.          case 194:
  427.          case 195:
  428.          case 198:
  429.          case 199:
  430.             return -1;
  431.          case 55:
  432.          case 57:
  433.          case 88:
  434.          case 97:
  435.          case 99:
  436.          case 101:
  437.          case 103:
  438.          case 105:
  439.          case 107:
  440.          case 109:
  441.          case 111:
  442.          case 113:
  443.          case 115:
  444.          case 127:
  445.          case 129:
  446.          case 131:
  447.          case 159:
  448.          case 160:
  449.          case 161:
  450.          case 162:
  451.          case 163:
  452.          case 164:
  453.          case 165:
  454.          case 166:
  455.          case 173:
  456.          case 175:
  457.             return -2;
  458.          case 79:
  459.          case 81:
  460.          case 83:
  461.          case 84:
  462.          case 85:
  463.          case 86:
  464.          case 148:
  465.          case 151:
  466.          case 152:
  467.             return -3;
  468.          case 80:
  469.          case 82:
  470.             return -4;
  471.          case 178:
  472.             return ((FieldDefinition)this.value).getType().stackSize();
  473.          case 179:
  474.             return -((FieldDefinition)this.value).getType().stackSize();
  475.          case 180:
  476.             return ((FieldDefinition)this.value).getType().stackSize() - 1;
  477.          case 181:
  478.             return -1 - ((FieldDefinition)this.value).getType().stackSize();
  479.          case 182:
  480.          case 183:
  481.          case 185:
  482.             return ((FieldDefinition)this.value).getType().getReturnType().stackSize() - (((FieldDefinition)this.value).getType().stackSize() + 1);
  483.          case 184:
  484.             return ((FieldDefinition)this.value).getType().getReturnType().stackSize() - ((FieldDefinition)this.value).getType().stackSize();
  485.          case 197:
  486.             return 1 - ((ArrayData)this.value).nargs;
  487.          default:
  488.             throw new CompilerError("invalid opcode: " + this.toString());
  489.       }
  490.    }
  491.  
  492.    int size(ConstantPool var1) {
  493.       switch (this.opc) {
  494.          case -3:
  495.          case -2:
  496.          case -1:
  497.             return 0;
  498.          case 0:
  499.             if (this.value != null && !(this.value instanceof Integer)) {
  500.                return 2;
  501.             }
  502.  
  503.             return 1;
  504.          case 16:
  505.          case 188:
  506.             return 2;
  507.          case 17:
  508.          case 153:
  509.          case 154:
  510.          case 155:
  511.          case 156:
  512.          case 157:
  513.          case 158:
  514.          case 159:
  515.          case 160:
  516.          case 161:
  517.          case 162:
  518.          case 163:
  519.          case 164:
  520.          case 165:
  521.          case 166:
  522.          case 167:
  523.          case 168:
  524.          case 198:
  525.          case 199:
  526.             return 3;
  527.          case 18:
  528.          case 19:
  529.             if (var1.index(this.value) < 256) {
  530.                this.opc = 18;
  531.                return 2;
  532.             }
  533.  
  534.             this.opc = 19;
  535.             return 3;
  536.          case 20:
  537.          case 178:
  538.          case 179:
  539.          case 180:
  540.          case 181:
  541.          case 182:
  542.          case 183:
  543.          case 184:
  544.          case 187:
  545.          case 189:
  546.          case 192:
  547.          case 193:
  548.             return 3;
  549.          case 21:
  550.          case 22:
  551.          case 23:
  552.          case 24:
  553.          case 25:
  554.             int var8 = ((Number)this.value).intValue();
  555.             if (var8 < 4) {
  556.                this.opc = 26 + (this.opc - 21) * 4 + var8;
  557.                return 1;
  558.             } else {
  559.                if (var8 <= 255) {
  560.                   return 2;
  561.                }
  562.  
  563.                this.opc += 256;
  564.                return 4;
  565.             }
  566.          case 54:
  567.          case 55:
  568.          case 56:
  569.          case 57:
  570.          case 58:
  571.             int var7 = this.value instanceof Number ? ((Number)this.value).intValue() : ((LocalVariable)this.value).slot;
  572.             if (var7 < 4) {
  573.                this.opc = 59 + (this.opc - 54) * 4 + var7;
  574.                return 1;
  575.             } else {
  576.                if (var7 <= 255) {
  577.                   return 2;
  578.                }
  579.  
  580.                this.opc += 256;
  581.                return 4;
  582.             }
  583.          case 132:
  584.             int var6 = ((int[])this.value)[0];
  585.             int var10 = ((int[])this.value)[1];
  586.             if (var6 <= 255 && (byte)var10 == var10) {
  587.                return 3;
  588.             }
  589.  
  590.             this.opc += 256;
  591.             return 6;
  592.          case 169:
  593.             int var5 = ((Number)this.value).intValue();
  594.             if (var5 <= 255) {
  595.                return 2;
  596.             }
  597.  
  598.             this.opc += 256;
  599.             return 4;
  600.          case 170:
  601.             SwitchData var4 = (SwitchData)this.value;
  602.  
  603.             int var9;
  604.             for(var9 = 1; (this.field_0 + var9) % 4 != 0; ++var9) {
  605.             }
  606.  
  607.             return var9 + 16 + (var4.maxValue - var4.minValue) * 4;
  608.          case 171:
  609.             SwitchData var2 = (SwitchData)this.value;
  610.  
  611.             int var3;
  612.             for(var3 = 1; (this.field_0 + var3) % 4 != 0; ++var3) {
  613.             }
  614.  
  615.             return var3 + 8 + var2.tab.size() * 8;
  616.          case 185:
  617.          case 200:
  618.          case 201:
  619.             return 5;
  620.          case 197:
  621.             return 4;
  622.          default:
  623.             return 1;
  624.       }
  625.    }
  626.  
  627.    void write(DataOutputStream var1, ConstantPool var2) throws IOException {
  628.       switch (this.opc) {
  629.          case 0:
  630.             if (this.value != null) {
  631.                if (this.value instanceof Integer) {
  632.                   var1.writeByte((Integer)this.value);
  633.                   return;
  634.                }
  635.  
  636.                var1.writeShort(var2.index(this.value));
  637.                return;
  638.             }
  639.          default:
  640.             var1.writeByte(this.opc);
  641.          case -3:
  642.          case -2:
  643.          case -1:
  644.             return;
  645.          case 16:
  646.          case 188:
  647.             var1.writeByte(this.opc);
  648.             var1.writeByte(((Number)this.value).intValue());
  649.             return;
  650.          case 17:
  651.             var1.writeByte(this.opc);
  652.             var1.writeShort(((Number)this.value).intValue());
  653.             return;
  654.          case 18:
  655.             var1.writeByte(this.opc);
  656.             var1.writeByte(var2.index(this.value));
  657.             return;
  658.          case 19:
  659.          case 20:
  660.          case 178:
  661.          case 179:
  662.          case 180:
  663.          case 181:
  664.          case 182:
  665.          case 183:
  666.          case 184:
  667.          case 187:
  668.          case 192:
  669.          case 193:
  670.             var1.writeByte(this.opc);
  671.             var1.writeShort(var2.index(this.value));
  672.             return;
  673.          case 21:
  674.          case 22:
  675.          case 23:
  676.          case 24:
  677.          case 25:
  678.          case 169:
  679.             var1.writeByte(this.opc);
  680.             var1.writeByte(((Number)this.value).intValue());
  681.             return;
  682.          case 54:
  683.          case 55:
  684.          case 56:
  685.          case 57:
  686.          case 58:
  687.             var1.writeByte(this.opc);
  688.             var1.writeByte(this.value instanceof Number ? ((Number)this.value).intValue() : ((LocalVariable)this.value).slot);
  689.             return;
  690.          case 132:
  691.             var1.writeByte(this.opc);
  692.             var1.writeByte(((int[])this.value)[0]);
  693.             var1.writeByte(((int[])this.value)[1]);
  694.             return;
  695.          case 153:
  696.          case 154:
  697.          case 155:
  698.          case 156:
  699.          case 157:
  700.          case 158:
  701.          case 159:
  702.          case 160:
  703.          case 161:
  704.          case 162:
  705.          case 163:
  706.          case 164:
  707.          case 165:
  708.          case 166:
  709.          case 167:
  710.          case 168:
  711.          case 198:
  712.          case 199:
  713.             var1.writeByte(this.opc);
  714.             var1.writeShort(((Instruction)this.value).field_0 - this.field_0);
  715.             return;
  716.          case 170:
  717.             SwitchData var8 = (SwitchData)this.value;
  718.             var1.writeByte(this.opc);
  719.  
  720.             for(int var9 = 1; (this.field_0 + var9) % 4 != 0; ++var9) {
  721.                var1.writeByte(0);
  722.             }
  723.  
  724.             var1.writeInt(var8.defaultLabel.field_0 - this.field_0);
  725.             var1.writeInt(var8.minValue);
  726.             var1.writeInt(var8.maxValue);
  727.  
  728.             for(int var10 = var8.minValue; var10 <= var8.maxValue; ++var10) {
  729.                Label var11 = var8.get(var10);
  730.                int var7 = var11 != null ? var11.field_0 : var8.defaultLabel.field_0;
  731.                var1.writeInt(var7 - this.field_0);
  732.             }
  733.  
  734.             return;
  735.          case 171:
  736.             SwitchData var3 = (SwitchData)this.value;
  737.             var1.writeByte(this.opc);
  738.  
  739.             for(int var4 = this.field_0 + 1; var4 % 4 != 0; ++var4) {
  740.                var1.writeByte(0);
  741.             }
  742.  
  743.             var1.writeInt(var3.defaultLabel.field_0 - this.field_0);
  744.             var1.writeInt(var3.tab.size());
  745.             Enumeration var5 = var3.sortedKeys();
  746.  
  747.             while(var5.hasMoreElements()) {
  748.                Integer var6 = (Integer)var5.nextElement();
  749.                var1.writeInt(var6);
  750.                var1.writeInt(var3.get(var6).field_0 - this.field_0);
  751.             }
  752.  
  753.             return;
  754.          case 185:
  755.             var1.writeByte(this.opc);
  756.             var1.writeShort(var2.index(this.value));
  757.             var1.writeByte(((FieldDefinition)this.value).getType().stackSize() + 1);
  758.             var1.writeByte(0);
  759.             return;
  760.          case 189:
  761.             var1.writeByte(this.opc);
  762.             var1.writeShort(var2.index(this.value));
  763.             return;
  764.          case 197:
  765.             var1.writeByte(this.opc);
  766.             var1.writeShort(var2.index(((ArrayData)this.value).type));
  767.             var1.writeByte(((ArrayData)this.value).nargs);
  768.             return;
  769.          case 200:
  770.          case 201:
  771.             var1.writeByte(this.opc);
  772.             var1.writeLong((long)(((Instruction)this.value).field_0 - this.field_0));
  773.             return;
  774.          case 277:
  775.          case 278:
  776.          case 279:
  777.          case 280:
  778.          case 281:
  779.          case 425:
  780.             var1.writeByte(196);
  781.             var1.writeByte(this.opc - 256);
  782.             var1.writeShort(((Number)this.value).intValue());
  783.             return;
  784.          case 310:
  785.          case 311:
  786.          case 312:
  787.          case 313:
  788.          case 314:
  789.             var1.writeByte(196);
  790.             var1.writeByte(this.opc - 256);
  791.             var1.writeShort(this.value instanceof Number ? ((Number)this.value).intValue() : ((LocalVariable)this.value).slot);
  792.             return;
  793.          case 388:
  794.             var1.writeByte(196);
  795.             var1.writeByte(this.opc - 256);
  796.             var1.writeShort(((int[])this.value)[0]);
  797.             var1.writeShort(((int[])this.value)[1]);
  798.       }
  799.    }
  800.  
  801.    public String toString() {
  802.       String var1 = (this.where >> 18) + ":\t";
  803.       switch (this.opc) {
  804.          case -3:
  805.             return var1 + "try " + ((TryData)this.value).getEndLabel().hashCode();
  806.          case -2:
  807.             return var1 + "dead";
  808.          case 132:
  809.             int var2 = ((int[])this.value)[0];
  810.             int var3 = ((int[])this.value)[1];
  811.             return var1 + RuntimeConstants.opcNames[this.opc] + " " + var2 + ", " + var3;
  812.          default:
  813.             if (this.value != null) {
  814.                if (this.value instanceof Label) {
  815.                   return var1 + RuntimeConstants.opcNames[this.opc] + " " + this.value.toString();
  816.                } else if (this.value instanceof Instruction) {
  817.                   return var1 + RuntimeConstants.opcNames[this.opc] + " " + this.value.hashCode();
  818.                } else {
  819.                   return this.value instanceof String ? var1 + RuntimeConstants.opcNames[this.opc] + " \"" + this.value + "\"" : var1 + RuntimeConstants.opcNames[this.opc] + " " + this.value;
  820.                }
  821.             } else {
  822.                return var1 + RuntimeConstants.opcNames[this.opc];
  823.             }
  824.       }
  825.    }
  826. }
  827.